<?php
namespace SDXApi\Controller;
use Think\Controller;
class IndexController extends Controller {
	public function _initialize(){
		
	}
    public function index(){
        set_time_limit(0);//让程序一直执行下去
        $str=520;
        $i=0;
        do{
           //$msg=date("Y-m-d H:i:s");
           file_put_contents("log.log",$str.'\n',FILE_APPEND);//记录日志
           $i++;
           sleep(1);//等待时间，进行下一次操作。单位为秒
        }while($i<10);
        /*$d = date('Y-m-d H:i:s', strtotime('+5 day 10:00')); 
        echo $d;
        $arr=array('id'=>'');
        echo json_encode($arr);
        exit;*/
       /* $time=time();
        $set_date_ymd=date('Y-m-d',$time);
        $set_time = $set_date_ymd."11:00";
        $set_time = strtotime($set_time);
        if($time > $set_time){
            echo 'bbbb';
        }else{
            echo 'aaaa';
        }
        echo '<br />'.$time.'=>'.$set_time;
        exit;*/
        /*
        $goods_weight=0.100;
        if($goods_weight){
            if($goods_weight>=1){
                $sku=$goods_weight;
            }else{
                $sku=$goods_weight/0.001;
            }
        }*/
        
       
       /*$d1 = strtotime('2016-12-13');//当前日期 
       $d2 = strtotime('2016-12-23');//保质期限
       $shelf_life=round(($d2-$d1)/3600/24);
       echo $shelf_life;
       exit;*/
       /* echo date('Y-m-d',strtotime('+1 day 2016-12-28'));
        exit;*/
        /*$Date_1 = date("Y-m-d");
        $Date_2 = "2016-12-30";
        $d1 = strtotime($Date_1);
        $d2 = strtotime($Date_2);
        $Days = round(($d2-$d1)/3600/24);
        echo  $Days . "D";
        exit;*/
        /*$time=time();
        $mac=md5('key4token'.$time);
        echo $time.'=>'.$mac.'<br />';
        exit;*/
        /*$str='103,104,105,106,107,108,136,137,123';
        $arr=explode(',', $str);
        $zoning_cate_mod=M('zoning_cate');
        foreach ($arr as $k=>$v){
            $data=array(
                'parent_id'=>9,
                'name'=>'',
                'z_val'=>$v,
                'is_status'=>1
            );
            $zoning_cate_mod->add($data);
            
        }
        echo 'Ok';
        exit;*/
        
       /* $arr1 = array(
  array('appid'=>'1111','sku'=>'aaaa'),
  array('appid'=>'222','sku'=>'bbbb'),
  array('appid'=>'333','sku'=>'cccc'),
  array('appid'=>'444','sku'=>'ddd')
);
$arr2 = array(
  array('appid'=>'1111','sku'=>'aaaa'),
  array('appid'=>'222','sku'=>'bbbb'),
  array('appid'=>'555','sku'=>'ee')
);
foreach($arr1 as $k=>$v) if(in_array($v, $arr2)) unset($arr1[$k]);
dump($arr1);*/
        /*$admin_user=M('Admin_user');
        $data=$admin_user->select();
        dump($data);*/
    	//$this->show('<style type="text/css">*{ padding: 0; margin: 0; } div{ padding: 4px 48px;} body{ background: #fff; font-family: "微软雅黑"; color: #333;font-size:24px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.8em; font-size: 36px } a,a:hover{color:blue;}</style><div style="padding: 24px 48px;"> <h1>:)</h1><p>欢迎使用 <b>食得鲜API</b>！</p></div>','utf-8');
       // dump(get_lng_lat('猎德大道46号尚东美御d1102'));
        
    }
    
    public function default_deliverytime($paytime,$day=1){
        if(empty($paytime)){
            $paytime=local_date('Y-m-d',time());
        }
        $delivery_time = local_strtotime($paytime.' +'.$day.' day '.C('DEFAULT_PRESELL_TIME_H'));
        $new_data = date('Y-m-d',$delivery_time);
        $delivery_time=strtotime($new_data." 20:30:00");
        $start_time=strtotime($new_data." 10:00:00");
        return array('delivery_time'=>$delivery_time,'start_time'=>$start_time);
    }
    
	public function test(){
		dump(S("sdxh5appid"));
		$this->display();
		$distribution_data = $this->get_distribution_by_gps('23.128971127288','113.34087793218');
		dump($distribution_data);
	}
	
	public function addr(){
	    header("Content-type: text/html; charset=utf-8");
	    $address=$_REQUEST['address'];
	    if($address){
	        $data=address_to_gps(str_ireplace(' ','',$address));
	        $latitude=$data['latitude'];
	        $longitude=$data['longitude'];
	        $arr=$this->get_distribution_by_gps($longitude, $latitude);
	        $arr['longitude']=$latitude;
	        $arr['latitude']=$longitude;
	        dump($arr);
	        exit;
	    }else{
	        echo '请输入如详细地址';
	        exit;
	    }
	}
	
	public function longlati(){
	    header("Content-type: text/html; charset=utf-8");
	    $longitude=$_REQUEST['long']; 
	    $latitude=$_REQUEST['lati'];
	    if(!empty($longitude) && !empty($latitude)){
	        $data=gps_to_address($latitude,$longitude);
	        echo 'all_address:'.$data['all_address']."<br/>";
	        echo 'lit_address:'.$data['lit_address']."<br/>";
	        exit;
	    }else{
	        echo '请输入经度纬度值的！';
	        exit;
	    }
	}
	
	public function addr_price(){
	    header("Content-type: text/html; charset=utf-8");
	    $longitude=$_REQUEST['long'];
	    $latitude=$_REQUEST['lati'];
	    if(!empty($longitude) && !empty($latitude)){
	        $data=$this->get_distribution_by_gps($latitude,$longitude);
	        dump($data);
	        exit;
	    }else{
	        echo '请输入经度纬度值的！';
	        exit;
	    }
	}
	
	/**
	 * 根据经纬度获取区域优惠信息
	 * @param $longitude
	 * @param $latitude
	 */
	public function get_distribution_by_gps($longitude, $latitude){
	    			$wdr_mod=M('warehouse_deliver_region');
	    			$wdrc_mod=M('warehouse_deliver_region_coordinates');
	    			$wdr=$wdr_mod->where(array('status'=>1))->select();
	    			if($wdr){
	    			    $polygon_free='';
	    			    $polygon_99_top='';
	    			    $polygon_99_bottom='';
	    			    $polygon_199='';
	    			    $polygon_69='';
	    			    $polygon_299='';
	    			    $polygon_39='';
	    			    $polygon_39_c='';
	    			    $polygon_399='';
	    			    foreach ($wdr as $key=>$val){
	    			        if($val['wdtype']==0){
	    			            $wdrc=$wdrc_mod->where(array('rid'=>$val['id']))->select();
	    			            if ($wdrc){
	    			                foreach ($wdrc as $k=>$v){
	    			                    $polygon_free[$val['id']][]=array('lat'=>$v['latitude'],'lng'=>$v['longitude'],'wid'=>$val['wid'],'wdr_id'=>$val['id'],'name'=>$val['name'],'start_price'=>$val['start_price'],'is_day'=>$val['is_day']);
	    			                }
	    			            }else {
	    			                continue;
	    			            }
	    			        }elseif($val['wdtype']==1){
	    			            $wdrc=$wdrc_mod->where(array('rid'=>$val['id']))->select();
	    			            if ($wdrc){
	    			                foreach ($wdrc as $k=>$v){
	    			                    $polygon_99_top[$val['id']][]=array('lat'=>$v['latitude'],'lng'=>(float)$v['longitude'],'wid'=>$val['wid'],'wdr_id'=>$val['id'],'name'=>$val['name'],'start_price'=>$val['start_price'],'is_day'=>$val['is_day']);
	    			                }
	    			            }else {
	    			                continue;
	    			            }
	    			        }elseif($val['wdtype']==2){
	    			            $wdrc=$wdrc_mod->where(array('rid'=>$val['id']))->select();
	    			            if ($wdrc){
	    			                foreach ($wdrc as $k=>$v){

	    			                    $polygon_99_bottom[$val['id']][]=array('lat'=>$v['latitude'],'lng'=>$v['longitude'],'wid'=>$val['wid'],'wdr_id'=>$val['id'],'name'=>$val['name'],'start_price'=>$val['start_price'],'is_day'=>$val['is_day']);
	    			                }
	    			            }else {
	    			                continue;
	    			            }
	    			        }elseif($val['wdtype']==3){
	    			            $wdrc=$wdrc_mod->where(array('rid'=>$val['id']))->select();
	    			            if ($wdrc){
	    			                foreach ($wdrc as $k=>$v){
	    			                    $polygon_199[$val['id']][]=array('lat'=>$v['latitude'],'lng'=>$v['longitude'],'wid'=>$val['wid'],'wdr_id'=>$val['id'],'name'=>$val['name'],'start_price'=>$val['start_price'],'is_day'=>$val['is_day']);
	    			                }
	    			            }else {
	    			                continue;
	    			            }
	    			        }elseif($val['wdtype']==4){
	    			            $wdrc=$wdrc_mod->where(array('rid'=>$val['id']))->select();
	    			            if ($wdrc){
	    			                foreach ($wdrc as $k=>$v){
	    			                    $polygon_69[$val['id']][]=array('lat'=>$v['latitude'],'lng'=>$v['longitude'],'wid'=>$val['wid'],'wdr_id'=>$val['id'],'name'=>$val['name'],'start_price'=>$val['start_price'],'is_day'=>$val['is_day']);
	    			                }
	    			            }else {
	    			                continue;
	    			            }
	    			        }elseif($val['wdtype']==5){
	    			            $wdrc=$wdrc_mod->where(array('rid'=>$val['id']))->select();
	    			            if ($wdrc){
	    			                foreach ($wdrc as $k=>$v){
	    			                    $polygon_299[$val['id']][]=array('lat'=>$v['latitude'],'lng'=>$v['longitude'],'wid'=>$val['wid'],'wdr_id'=>$val['id'],'name'=>$val['name'],'start_price'=>$val['start_price'],'is_day'=>$val['is_day']);
	    			                }
	    			            }else {
	    			                continue;
	    			            }
	    			        }elseif($val['wdtype']==6){
	    			            $wdrc=$wdrc_mod->where(array('rid'=>$val['id']))->select();
	    			            if ($wdrc){
	    			                foreach ($wdrc as $k=>$v){
	    			                    $polygon_39[$val['id']][]=array('lat'=>$v['latitude'],'lng'=>$v['longitude'],'wid'=>$val['wid'],'wdr_id'=>$val['id'],'name'=>$val['name'],'start_price'=>$val['start_price'],'is_day'=>$val['is_day']);
	    			                }
	    			            }else {
	    			                continue;
	    			            }
	    			        }elseif($val['wdtype']==7){
	    			            $wdrc=$wdrc_mod->where(array('rid'=>$val['id']))->select();
	    			            if ($wdrc){
	    			                foreach ($wdrc as $k=>$v){
	    			                    $polygon_399[$val['id']][]=array('lat'=>$v['latitude'],'lng'=>$v['longitude'],'wid'=>$val['wid'],'wdr_id'=>$val['id'],'name'=>$val['name'],'start_price'=>$val['start_price'],'is_day'=>$val['is_day']);
	    			                }
	    			            }else {
	    			                continue;
	    			            }
	    			        }elseif($val['wdtype']==8){
	    			            $wdrc=$wdrc_mod->where(array('rid'=>$val['id']))->select();
	    			            if ($wdrc){
	    			                foreach ($wdrc as $k=>$v){
	    			                    $polygon_39_c[$val['id']][]=array('lat'=>$v['latitude'],'lng'=>$v['longitude'],'wid'=>$val['wid'],'wdr_id'=>$val['id'],'name'=>$val['name'],'start_price'=>$val['start_price'],'is_day'=>$val['is_day']);
	    			                }
	    			            }else {
	    			                continue;
	    			            }
	    			        }
	    			    }
	    			}else{
	    			    returnApiError('无法匹配到仓库');
	    			}
	    			if($polygon_free){
        	    			foreach ($polygon_free as $key=>$val){
        	    			    foreach ($val as $k=>$v){
        	    			        $free[$k]=array('lat'=>$v['lat'],'lng'=>$v['lng'],'wid'=>$v['wid'],'wdr_id'=>$v['wdr_id'],'name'=>$v['name'],'start_price'=>$v['start_price'],'is_day'=>$v['is_day']);
        	    			    }
        	    			    $data=$this->isPointInPolygon($free,$longitude,$latitude);
        	    			    if($data){
        	    			        $arr['wid'] = $free[0]['wid'];
        	    			        $arr['wdr_id'] = $free[0]['wdr_id'];
        	    			        $arr['qyname'] = $free[0]['name'];
        	    			        $arr['name'] = "free";
        	    			        $arr['prescription'] = "3小时";
        	    			        $arr['is_day']=$free[0]['is_day'];
        	    			        return $arr;

        	    			    }
        	    			    unset($data);
        	    			    unset($free);
        	    			}
	    			}

	    			if($polygon_99_top){
	    			     foreach ($polygon_99_top as $key=>$val){
        	    			    foreach ($val as $k=>$v){
        	    			        $top[$k]=array('lat'=>$v['lat'],'lng'=>$v['lng'],'wid'=>$v['wid'],'wdr_id'=>$v['wdr_id'],'name'=>$v['name'],'start_price'=>$v['start_price'],'is_day'=>$v['is_day']);
        	    			    }
        	    			    $data=$this->isPointInPolygon($top,$longitude,$latitude);
        	    			    if($data){
        	    			        $arr['wid'] = $top[0]['wid'];
        	    			        $arr['wdr_id'] = $top[0]['wdr_id'];
        	    			        $arr['qyname'] = $top[0]['name'];
        	    			        $arr['name'] = "99";
        	    			        $arr['prescription'] = "24小时";
        	    			        $arr['is_day']=$top[0]['is_day'];
        	    			        return $arr;
        	    			    }
        	    			    unset($top);
        	    			    unset($data);
        	    		}
	    			}
	    			if($polygon_99_bottom){
	    			    foreach ($polygon_99_bottom as $key=>$val){
	    			        foreach ($val as $k=>$v){
	    			            $bottom[$k]=array('lat'=>$v['lat'],'lng'=>$v['lng'],'wid'=>$v['wid'],'wdr_id'=>$v['wdr_id'],'name'=>$v['name'],'start_price'=>$v['start_price'],'is_day'=>$v['is_day']);
	    			        }
	    			        $data=$this->isPointInPolygon($bottom,$longitude,$latitude);
	    			        if($data){
	    			               $arr['wid'] = $bottom[0]['wid'];
        	    			        $arr['wdr_id'] = $bottom[0]['wdr_id'];
        	    			        $arr['qyname'] = $bottom[0]['name'];
        	    			        $arr['name'] = "99";
        	    			        $arr['prescription'] = "24小时";
        	    			        $arr['is_day']=$bottom[0]['is_day'];
        	    			        return $arr;
	    			        }
	    			        unset($bottom);
	    			        unset($data);
	    			    }
	    			}
	    			if($polygon_199){
	    			    foreach ($polygon_199 as $key=>$val){
	    			        foreach ($val as $k=>$v){
	    			            $p199[$k]=array('lat'=>$v['lat'],'lng'=>$v['lng'],'wid'=>$v['wid'],'wdr_id'=>$v['wdr_id'],'name'=>$v['name'],'start_price'=>$v['start_price'],'is_day'=>$v['is_day']);
	    			        }
	    			        $data=$this->isPointInPolygon($p199,$longitude,$latitude);
	    			        if($data){
	    			            $arr['wid'] = $p199[0]['wid'];
        	    			        $arr['wdr_id'] = $p199[0]['wdr_id'];
        	    			        $arr['qyname'] = $p199[0]['name'];
        	    			        $arr['name'] = "199";
        	    			        $arr['prescription'] = "24小时";
        	    			        $arr['is_day']=$p199[0]['is_day'];
        	    			        return $arr;
	    			        }
	    			        unset($p199);
	    			        unset($data);
	    			    }
	    			}
	    			if($polygon_69){
	    			    foreach ($polygon_69 as $key=>$val){
	    			        foreach ($val as $k=>$v){
	    			            $p69[$k]=array('lat'=>$v['lat'],'lng'=>$v['lng'],'wid'=>$v['wid'],'wdr_id'=>$v['wdr_id'],'name'=>$v['name'],'start_price'=>$v['start_price'],'is_day'=>$v['is_day']);
	    			        }
	    			        $data=$this->isPointInPolygon($p69,$longitude,$latitude);
	    			        if($data){
	    			           $arr['wid'] = $p69[0]['wid'];
        	    			        $arr['wdr_id'] = $p69[0]['wdr_id'];
        	    			        $arr['qyname'] = $p69[0]['name'];
        	    			        $arr['name'] = "free";
        	    			        $arr['prescription'] = "3小时";
        	    			        $arr['is_day']=$p69[0]['is_day'];
        	    			        return $arr;
	    			        }
	    			        unset($p69);
	    			        unset($data);
	    			    }
	    			}
	    			if($polygon_299){
	    			    foreach ($polygon_299 as $key=>$val){
	    			        foreach ($val as $k=>$v){
	    			            $p299[$k]=array('lat'=>$v['lat'],'lng'=>$v['lng'],'wid'=>$v['wid'],'wdr_id'=>$v['wdr_id'],'name'=>$v['name'],'start_price'=>$v['start_price'],'is_day'=>$v['is_day']);
	    			        }
	    			        $data=$this->isPointInPolygon($p299,$longitude,$latitude);
	    			        if($data){
	    			            $arr['wid'] = $p299[0]['wid'];
	    			            $arr['wdr_id'] = $p299[0]['wdr_id'];
	    			            $arr['qyname'] = $p299[0]['name'];
	    			            $arr['name'] = "299";
	    			            $arr['prescription'] = "24小时";
	    			            $arr['is_day']=$p299[0]['is_day'];
	    			            return $arr;
	    			        }
	    			        unset($p299);
	    			        unset($data);
	    			    }
	    			}
	    			if($polygon_39){
	    			    foreach ($polygon_39 as $key=>$val){
	    			        foreach ($val as $k=>$v){
	    			            $p39[$k]=array('lat'=>$v['lat'],'lng'=>$v['lng'],'wid'=>$v['wid'],'wdr_id'=>$v['wdr_id'],'name'=>$v['name'],'start_price'=>$v['start_price'],'is_day'=>$v['is_day']);
	    			        }
	    			        $data=$this->isPointInPolygon($p39,$longitude,$latitude);
	    			        if($data){
	    			            $arr['wid'] = $p39[0]['wid'];
	    			            $arr['wdr_id'] = $p39[0]['wdr_id'];
	    			            $arr['qyname'] = $p39[0]['name'];
	    			            $arr['name'] = "39";
	    			            $arr['prescription'] = "3小时";
	    			            $arr['is_day']=$p39[0]['is_day'];
	    			            return $arr;
	    			        }
	    			        unset($p39);
	    			        unset($data);
	    			    }
	    			}
	    			if($polygon_39_c){
	    			    foreach ($polygon_39_c as $key=>$val){
	    			        foreach ($val as $k=>$v){
	    			            $p39_c[$k]=array('lat'=>$v['lat'],'lng'=>$v['lng'],'wid'=>$v['wid'],'wdr_id'=>$v['wdr_id'],'name'=>$v['name'],'start_price'=>$v['start_price'],'is_day'=>$v['is_day']);
	    			        }
	    			        $data=$this->isPointInPolygon($p39_c,$longitude,$latitude);
	    			        if($data){
	    			            $arr['wid'] = $p39_c[0]['wid'];
	    			            $arr['wdr_id'] = $p39_c[0]['wdr_id'];
	    			            $arr['qyname'] = $p39_c[0]['name'];
	    			            $arr['name'] = "39";
	    			            $arr['prescription'] = "24小时";
	    			            $arr['is_day']=$p39_c[0]['is_day'];
	    			            return $arr;
	    			        }
	    			        unset($p39_c);
	    			        unset($data);
	    			    }
	    			}
	    			if($polygon_399){
	    			    foreach ($polygon_399 as $key=>$val){
	    			        foreach ($val as $k=>$v){
	    			            $p399[$k]=array('lat'=>$v['lat'],'lng'=>$v['lng'],'wid'=>$v['wid'],'wdr_id'=>$v['wdr_id'],'name'=>$v['name'],'start_price'=>$v['start_price'],'is_day'=>$v['is_day']);
	    			        }
	    			        $data=$this->isPointInPolygon($p399,$longitude,$latitude);
	    			        if($data){
	    			            $arr['wid'] = $p399[0]['wid'];
	    			            $arr['wdr_id'] = $p399[0]['wdr_id'];
	    			            $arr['qyname'] = $p399[0]['name'];
	    			            $arr['name'] = "399";
	    			            $arr['prescription'] = "24小时";
	    			            $arr['is_day']=$p399[0]['is_day'];
	    			            return $arr;
	    			        }
	    			        unset($p399);
	    			        unset($data);
	    			    }
	    			}
	    			return false;



	}

	public function isPointInPolygon_y($polygon,$longitude,$latitude){
	    $count = count($polygon);
	    $testx = $longitude;
	    $testy = $latitude;
	    $c=false;
	    for ($i=0,$j=$count-1;$i<$count;$j=$i++){
	        $sy=$polygon[$i]['lng'];
	        $sx=$polygon[$i]['lat'];
	        $ty=$polygon[$j]['lng'];
	        $tx=$polygon[$j]['lat'];
	        $wid=$polygon[$i]['wid'];
	        $wdr_id=$polygon[$i]['wdr_id'];
	        $name=$polygon[$i]['name'];
	        $price=$polygon[$i]['start_price'];
	        $data=array('wid'=>$wid,'wdr_id'=>$wdr_id,'qyname'=>$name,'price'=>$price);
	        if(((($sy>$testy)!=($ty>$testy)))&&($testx<($tx-$sx)*($testy-$sy)/($ty-$sy)+$sy)){
	            $c=!$c;
	            if($c){
	                return $data;
	            }
	        }
	    }
	    return $c;
	    
	}
	

	public function isPointInPolygon_x($polygon,$longitude,$latitude){
	    $count = count($polygon);
	    $px = $longitude;
	    $py = $latitude;
	    $flag = false;
	    $k=0;
	    for($i=0;$i<$count;$i++){
	        $sy=$polygon[$i]['lng'];
	        $sx=$polygon[$i]['lat'];
	        $j=($i+1)%$count;
	        $ty=$polygon[$j]['lng'];
	        $tx=$polygon[$j]['lat'];
	        $wid=$polygon[$i]['wid'];
	        $wdr_id=$polygon[$i]['wdr_id'];
	        $name=$polygon[$i]['name'];
	        $price=$polygon[$i]['start_price'];
	        $data=array('wid'=>$wid,'wdr_id'=>$wdr_id,'qyname'=>$name,'price'=>$price);
	        if($sy==$ty){
	            if($py==$sy && $px>=min($sx,$tx) && $px<=max($sx,$tx)){
	                return $data;
	            }
	            continue;
	        }
	        if($py<min($sy,$ty) || $py>max($sy,$ty)){
	            continue;
	        }
	        $x=(double)((double)($py-$sy)*(double)($ty-$sx)/(double)($ty-$sy)+$sx);
	        if($x>$px){
	            $k++;
	        }elseif (x==$px){
	            return $data;
	        }
	        
	        if($k%2==1){
	            return $data;
	        }
	        
	       return false;
	    }
	}
	
	
	public function xxx(){
	    header("Content-type: text/html; charset=utf-8");
	    $longitude=$_REQUEST['long'];
	    $latitude=$_REQUEST['lati'];
	    $polygon=array(
	        /*1号*/
	        /*array('lng'=>(float)113.351187,'lat'=>(float)23.131810),
	        array('lng'=>(float)113.353311,'lat'=>(float)23.131698),
	        array('lng'=>(float)113.354331,'lat'=>(float)23.131602),
	        array('lng'=>(float)113.358513,'lat'=>(float)23.130871),
	        array('lng'=>(float)113.363089,'lat'=>(float)23.130186),
	        array('lng'=>(float)113.364733,'lat'=>(float)23.129858),
	        array('lng'=>(float)113.368686,'lat'=>(float)23.129097),
	        array('lng'=>(float)113.373896,'lat'=>(float)23.127672),
	        array('lng'=>(float)113.378010,'lat'=>(float)23.126688),
	        array('lng'=>(float)113.381208,'lat'=>(float)23.125890),
	        array('lng'=>(float)113.380903,'lat'=>(float)23.123605),
	        array('lng'=>(float)113.380808,'lat'=>(float)23.121183),
	        array('lng'=>(float)113.380795,'lat'=>(float)23.118931),
	        array('lng'=>(float)113.380786,'lat'=>(float)23.116717),
	        array('lng'=>(float)113.374439,'lat'=>(float)23.115441),
	        array('lng'=>(float)113.366804,'lat'=>(float)23.115051),
	        array('lng'=>(float)113.364787,'lat'=>(float)23.115429),
	        array('lng'=>(float)113.363085,'lat'=>(float)23.115666),
	        array('lng'=>(float)113.358243,'lat'=>(float)23.116252),
	        array('lng'=>(float)113.358616,'lat'=>(float)23.121474),
	        array('lng'=>(float)113.358719,'lat'=>(float)23.122899),
	        array('lng'=>(float)113.354286,'lat'=>(float)23.123007),
	        array('lng'=>(float)113.349929,'lat'=>(float)23.123244),
	        array('lng'=>(float)113.349970,'lat'=>(float)23.125147),
	        array('lng'=>(float)113.350001,'lat'=>(float)23.127618),
	        array('lng'=>(float)113.350082,'lat'=>(float)23.130917),
	        array('lng'=>(float)113.350028,'lat'=>(float)23.131889)*/
	        
	        /* 5号*/
	        array('lng'=>(float)113.334411,'lat'=>(float)23.122392),
	        array('lng'=>(float)113.334402,'lat'=>(float)23.121196),
	        array('lng'=>(float)113.331083,'lat'=>(float)23.121466),
	        array('lng'=>(float)113.331051,'lat'=>(float)23.123547),
	        array('lng'=>(float)113.331114,'lat'=>(float)23.124860),
	        array('lng'=>(float)113.331123,'lat'=>(float)23.126169),
	        array('lng'=>(float)113.331213,'lat'=>(float)23.129214),
	        array('lng'=>(float)113.334559,'lat'=>(float)23.128927),
	        array('lng'=>(float)113.334415,'lat'=>(float)23.124602),
	    );
	    $data=$this->isPointInPolygonxx($polygon,$latitude,$longitude);
	    dump($data);
	    exit;
	}
	
	private function isPointInPolygonxx($polygon, $longitude, $latitude){
	    
	    $count = count($polygon);
	    $px = $longitude;
	    $py = $latitude;
	    $flag = false;
	    for ($i = 0, $j = $count - 1; $i < $count; $j = $i, $i++) {
	        $sy = $polygon[$i]['lng'];
	        $sx = $polygon[$i]['lat'];
	        $ty = $polygon[$j]['lng'];
	        $tx = $polygon[$j]['lat'];
	        if ($px == $sx && $py == $sy || $px == $tx && $py == $ty)
	        {
	            return true;
	        }
	        if ($sy < $py && $ty >= $py || $sy >= $py && $ty < $py) {
	            $x = $sx + ($py - $sy) * ($tx - $sx) / ($ty - $sy);
	            if ($x == $px){
	                return true;
	            }
	            if ($x > $px){
	                $flag = !$flag;
	               
	            }
	
	        }
	    }
	     
	    return $flag;
	}
	
	
	
/**
     * 射线法计算坐标是否在规定图形内
     * @param $polygon
     * @param $longitude
     * @param $latitude
     * @return bool
     */
     private function isPointInPolygon($polygon, $longitude, $latitude){
        $count = count($polygon);
        $px = $longitude;
        $py = $latitude;
        $flag = false;
        for ($i = 0, $j = $count - 1; $i < $count; $j = $i, $i++) {
            $sy = $polygon[$i]['lng'];
            $sx = $polygon[$i]['lat'];
            $ty = $polygon[$j]['lng'];
            $tx = $polygon[$j]['lat'];
            if ($px == $sx && $py == $sy || $px == $tx && $py == $ty)
            {   
                return true;
            }
            if ($sy < $py && $ty >= $py || $sy >= $py && $ty < $py) {
                $x = $sx + ($py - $sy) * ($tx - $sx) / ($ty - $sy);
                if ($x == $px){
                    return true;
                }
                if ($x > $px){
                    $flag = !$flag; 
                }
                    
            }
        }
            return $flag; 
    }
	
	public function send(){
	    $array=array(
	        'messcode'=>'order_distribution',
	        'mobile'=>'15820245055',
	        'consignee'=>'马张健',
	        'user_rank'=>'',
	        'order_sn'=>'123456',
	        'ver_code'=>'',
	        'user_id'=>'41'
	    );
	    dump(sdx_sendsms($array));
	}
	
	public function pupdate(){
	    //M('goods')->where(array('is_presell'=>0,'delivery_type'=>0,'delivery_cycle'=>0))->select();
	   //UPDATE sdx_goods SET is_presell=1,delivery_type=2,delivery_cycle=1  WHERE is_presell=0 and delivery_type=0 and delivery_cycle=0
	}
}